<template>
  <div class="login-container">
    <h2>登录</h2>
    <el-form :model="loginForm" @submit.native.prevent="handleLogin">
      <el-form-item label="用户名">
        <el-input v-model="loginForm.username" placeholder="请输入用户名"></el-input>
      </el-form-item>
      <el-form-item label="密　码">
        <el-input type="password" v-model="loginForm.password" placeholder="请输入密码"></el-input>
      </el-form-item>
      <el-form-item>
          <el-button type="primary" native-type="submit">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { ref } from 'vue'; 
import { adminUserService } from '@/api/adminUser'; // 更新导入路径
import { useRouter } from 'vue-router';
const router = useRouter();
const loginForm = ref({
  username: '',
  password: ''
});

const handleLogin = () => {
    const { username, password } = loginForm.value;
    adminUserService.login({username,password})
      .then(response => {
        // 登录成功后，可以进行后续操作，比如跳转到首页
        router.push('/');
      })
      .catch(error => {
        console.log(error);
        // 登录失败后，可以进行错误处理，比如显示错误消息
      })
};
</script>

<style scoped>
.login-container {
  max-width: 300px;
  margin: 0 auto;
  padding: 20px;
  border: 1px solid #ccc;
  border-radius: 5px;
  box-shadow: 2px 2px 12px #aaa;
  position: fixed;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.login-container h2 {
  text-align: center;
}
</style>